//some functions to use by MrUI Objects
var Utils = Utils || {};

Utils.tableToJSObj = function(){
    if(arguments.length == 0)
        throw "No arguments error";
    
    var table = arguments[0];
    
    var options = Array.from(arguments).slice(1);
    
    var jsoTable = {};
    
    var hd = $(table).getElements('th').map(function(item){
        return item.innerText;
    });
    
    jsoTable['header'] = hd;
    
    alert("obj: " + jsoTable);
};

Utils.root = null
    
Utils.getVariableFromPath = function(path){
    if(!path) throw "No path error";
    
    //webbrowser
    Utils.root = Utils.root || window;
    
    if(!Utils.root) throw "No global context defined"
    
    var pathArray = path.split('.');
    var cvar = Utils.root;
    
    pathArray.each(function(x, i){
        cvar = cvar[x];
        if(!cvar) return null;
    });
    
    return cvar;
};

Utils.execFunctionFromPath = function(){
    if(arguments.length == 0)
        throw "No path error";
    
    var path = arguments[0];
    var args = Array.prototype.slice.call(arguments, 1);
    var func = Utils.getVariableFromPath(path);
    
    if (func instanceof Function)
        return func.apply(this, args);
    
    func(); 
};


